package com.xinchuang.mapper.targetSystem.config;

import com.xinchuang.entity.targetSystem.config.SystemConfig;
import com.xinchuang.entity.targetSystem.config.SystemParam;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @ClassName SystemParam
 * @Description: TODO(写一段描述的话)
 * @Author zhangxuan
 * @Date 2023-08-07 11:07
 * @Verion V1.0
 */
public interface SystemParamMapper {

    @Insert(value = "INSERT INTO system_param (id,key_value,key_name,value,remark,type,create_time) VALUES (#{id},#{keyValue},#{keyName},#{value},#{remark},#{type},CURRENT_TIMESTAMP)")
    int addSystemParam(SystemParam systemParam);

    @Select(value = {
            "SELECT id,key_value,key_name,value,remark,type FROM system_param WHERE key_value = #{key}"
    })
    @Results(value = {
            @Result(property = "keyName", column = "key_name")
    })
    SystemParam selectSystemParamOnly(String key);

    @Select(value = {
            "SELECT id,key_value,key_name,value,remark,type FROM system_param WHERE id = #{id}"
    })
    @Results(value = {
            @Result(property = "keyName", column = "key_name")
    })
    SystemParam selectSystemParamIdOnly(String id);

    @Delete(value = "DELETE FROM system_param WHERE id = #{id}")
    int deleteSystemParam(String id);

    @Update(value = {
            "<script>",
            "UPDATE system_param ",
            "<set>",
            "<if test = 'keyValue != null'>key_value = #{keyValue},</if>",
            "<if test = 'keyName != null'>key_name = #{keyName},</if>",
            "remark = #{remark},",
            "<if test = 'value != null'>value = #{value},</if>",
            "</set>",
            "WHERE id = #{id}",
            "</script>"
    })
    int updateSystemParam(SystemParam systemParam);

    @Select(value = {
            "SELECT id,key_value,key_name,value,remark FROM system_param"
    })
    @Results(value = {
            @Result(property = "keyName", column = "key_name")
    })
    List<SystemParam> selectSystemParamList();

}
